<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>06.vue中多个元素或组件的过度</title>
    <link rel="stylesheet" href="animate.css">
</head>
<style>
    .fade-enter, .fade-leave-to {
        opacity: 0;
    }
    .fade-enter-active, .fade-leave-active {
        transition: opacity 1s;
    }
</style>
<body>
    <div id="app">
        <transition name="fade" mode="in-out">
            <component :is="type"></component>
            <!-- <child-one v-if="show"></child-one>
            <child-two v-else></child-two> -->
  <!--           <div v-if="show" key="hello">hello world</div>
            <div v-else key="bye">Bye world</div> -->
        </transition>

        <button @click="handleClick">切换</button>
    </div>
</body>
<script src="vue.js"></script>
<script>
    Vue.component('child-one', {
        template: '<div>child-one</div>'
    })
    Vue.component('child-two', {
        template: '<div>child-two</div>'
    })
    var app = new Vue({
        el: '#app',
        data: {
            show: true,
            type: 'child-one'
        },
        methods: {
            handleClick: function() {
                this.show = !this.show;
                this.type = this.type == 'child-one'? 'child-two' : 'child-one'
            }
        }
    })
</script>
</html>